jQuery.fn.rotate = function(angle,whence) {
	var p = this.get(0);
	var div = $(this).parent();
	
	// we store the angle inside the image tag for persistence
	if (!whence) {
		p.angle = ((p.angle==undefined?0:p.angle) + angle) % 360;
	} else {
		p.angle = angle;
	}

	if (p.angle >= 0) {
		var rotation = Math.PI * p.angle / 180;
	} else {
		var rotation = Math.PI * (360+p.angle) / 180;
	}
	debugger;
	var costheta = Math.cos(rotation);
	var sintheta = Math.sin(rotation);
	if (document.all && !window.opera) {
		p.style.filter = "progid:DXImageTransform.Microsoft.Matrix(M11="+costheta+",M12="+(-sintheta)+",M21="+sintheta+",M22="+costheta+",SizingMethod='auto expand')";
		var bigImg = div.find("div[class='zoomWrapperImage']").find("img");
		bigImg.css({"filter":"progid:DXImageTransform.Microsoft.Matrix(M11="+costheta+",M12="+(-sintheta)+",M21="+sintheta+",M22="+costheta+",SizingMethod='auto expand')"})
	} else {
		//p.style="-webkit-transform=rotate("+angle+"deg)";
		var img = $(p);
		img.css("transform-origin","50% 50% 0");
		img.css("-moz-transform","rotate("+p.angle+"deg)");
		img.css("-webkit-transform","rotate("+p.angle+"deg)");
		//$(".omWrapperImage").find("img").css("-webkit-transform","rotate("+p.angle+"deg)");
		//zoomWrapperImage
		var a = img.parents("a");
		var bigImg = a.find("div[class='zoomWrapperImage']").find("img");
//		if(bigImg.length==0){
//			a.find("div[class='zoomWrapperImage']").append("<img/>")
//		}
		//a.find("div[class='zoomWrapperImage']").find("img").css("-webkit-transform","rotate("+p.angle+"deg)");
		bigImg.css("-webkit-transform","rotate("+p.angle+"deg)");
		bigImg.css("-moz-transform","rotate("+p.angle+"deg)");
		
	}
}

jQuery.fn.rotateRight = function(angle) {
	this.rotate(angle==undefined?90:angle);
}

jQuery.fn.rotateLeft = function(angle) {
	this.rotate(angle==undefined?-90:-angle);
}
